package cn.tedu.csmall.stock.webapi.quartz;

import cn.tedu.csmall.stock.webapi.config.RabbitMQConfig;
import cn.tedu.csmall.stock.webapi.utils.RedisBloomUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

public class QuartzJob implements Job {
    //RabbitTemplate工具类
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
    @Autowired
    private RedisBloomUtils redisBloomUtils;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //要执行的任务,比如输出当前时间
       // System.out.println("-------------"+ LocalDateTime.now() +"-------------");
//        LocalDateTime now = LocalDateTime.now();
        //convertAndSend([交换机名称],[路由key的名称],[要发送的消息])
        //发送的消息，自动帮我们转成byte[]类型
//        rabbitTemplate.convertAndSend(RabbitMQConfig.STOCK_EX,RabbitMQConfig.STOCK_ROUTE,now);
        //定义向布隆过滤器中保存的元素
        String[] colors = {"red","origin","yellow","green","blue","pink"};
        redisBloomUtils.bfmadd("colorBloom",colors);
        //定义要检查的字符
        String elm1 = "red";
        String elm2 = "black";
        //输出判断结果
        System.out.println("判断"+elm1+"是否在布隆过滤器中："+redisBloomUtils.bfexists("colorBloom",elm1));
        System.out.println("判断"+elm2+"是否在布隆过滤器中："+redisBloomUtils.bfexists("colorBloom",elm2));
    }
}
